home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
CWWatcher.cp
< prev
next >
Wrap
Text File
|
1997-06-28
|
7KB
|
351 lines
// CWWatcher.cp
#ifndef CWWatcher_h
#include "CWWatcher.h"
#endif
#ifndef ProcessLoop_h
#include "ProcessLoop.h"
#endif
#ifndef ProcessInfo_h
#include "ProcessInfo.h"
#endif
#ifndef WindowObject_h
#include "WindowObject.h"
#endif
#ifndef OSError_h
#include "OSError.h"
#endif
#ifndef BufferOfSize_h
#include "BufferOfSize.h"
#endif
#ifndef CompileStatistics_h
#include "CompileStatistics.h"
#endif
CompileStatistics CWWatcher::stats;
CWWatcher::CWWatcher()
: QDPatchBlock( const_cast<GrafPortObject&>( ToolBar()->Port() ) ),
fileLine( 0 ),
oldLines( 0 ),
numberToIgnore( maxuint32 ),
totalLines( 0 ),
filesLeft( 0 )
{
ActivateTextPatch();
Count();
}
CWWatcher::~CWWatcher()
{
if ( stats.Known( file ) )
{
uint32 oldFileLines = stats.FileLines( file );
if ( oldFileLines > fileLine )
{
totalLines -= oldFileLines - fileLine;
stats.SetFileLines( file, fileLine );
}
}
}
void CWWatcher::DrawText( ConstData text,
Point numerator,
Point denominator )
{
QDPatchBlock::DrawText( text, numerator, denominator );
uint32 lineStart;
for ( lineStart = 0; lineStart + 6 < text.Length(); lineStart++ )
if ( text[lineStart] == 'L'
&& text[lineStart + 1] == 'i'
&& text[lineStart + 2] == 'n'
&& text[lineStart + 3] == 'e'
&& text[lineStart + 4] == ':' )
break;
if ( lineStart + 6 < text.Length() )
{
String255 numeral( text.Tail( lineStart + 6 ) );
StringToNum( numeral, &fileLine );
if ( fileLine == numberToIgnore )
fileLine = 0;
else
numberToIgnore = maxuint32;
if ( stats.Known( file ) )
{
uint32 oldFileLines = stats.FileLines( file );
if ( oldFileLines < fileLine )
{
totalLines += fileLine - oldFileLines;
stats.SetFileLines( file, fileLine );
}
}
}
else if ( text.StartsWith( ConstPString( "\pCompiling: " ) ) )
{
String255 newFile( text.Middle( URange32( 12, text.Length() - 1 ) ) );
if ( ConstPString(newFile) == ConstPString(file) )
return;
if ( stats.Known( file ) )
{
uint32 oldFileLines = stats.FileLines( file );
if ( oldFileLines > fileLine )
{
totalLines -= oldFileLines - fileLine;
stats.SetFileLines( file, fileLine );
}
}
oldLines += fileLine;
numberToIgnore = fileLine;
fileLine = 0;
if ( file.Length() != 0 )
filesLeft--;
file = newFile;
}
Announce();
}
ConstData CWWatcher::Partition()
{
for ( ProcessLoop process; process.Unfinished(); process++ )
{
ProcessInfo info( *process );
if ( info.Signature() == FileSignature::Make( 'CWIE' ) )
return info.Partition();
}
return ConstData();
}
const WindowObject *CWWatcher::ToolBar()
{
ConstData partition( Partition() );
for ( uint32 offset = 0; offset < partition.Length(); offset+=4 )
{
const WindowObject *w = reinterpret_cast<const WindowObject *>( &partition[offset] );
if ( w->windowKind == 0x4e20
&& w->port.portRect.right == 465
&& w->port.portRect.bottom == 17
&& w->port.portRect.left == 0
&& w->port.portRect.top == 0
&& w->titleWidth == 0
&& w->controlList == 0
&& w->windowPic == 0 )
return w;
}
return 0;
}
void CWWatcher::Count()
{
OSType signature = 'CWIE';
AEAddressDesc address;
OSError error = AECreateDesc( typeApplSignature,
&signature,
sizeof( signature ),
&address );
error.Debug();
error.Throw();
AppleEvent event;
error = AECreateAppleEvent( 'MMPR',
'GSeg',
&address,
kAutoGenerateReturnID,
kAnyTransactionID,
&event );
error.Debug();
error.Throw();
AppleEvent reply;
error = AESend( &event,
&reply,
kAEWaitReply,
kAENeverInteract,
5 * 60 * 60,
0,
0 );
error.Debug();
error.Throw();
AEDescList segmentList;
error = AEGetParamDesc( &reply, keyDirectObject, typeAEList, &segmentList );
error.Debug();
error.Throw();
error = AEDisposeDesc( &reply );
error.Debug();
error.Throw();
int32 segmentCount;
error = AECountItems( &segmentList, &segmentCount );
error.Debug();
error.Throw();
filesLeft = 0;
for ( uint16 segmentNumber = 1; segmentNumber <= segmentCount; segmentNumber++ )
{
AERecord segmentRecord;
OSType key;
error = AEGetNthDesc( &segmentList,
segmentNumber,
typeAERecord,
&key,
&segmentRecord );
error.Debug();
error.Throw();
uint16 fileCount;
int32 actualSize;
OSType type;
error = AEGetKeyPtr( &segmentRecord,
'NumF',
typeSMInt,
&type,
&fileCount,
sizeof( fileCount ),
&actualSize );
error.Debug();
error.Throw();
Assert( actualSize == sizeof( fileCount ) );
for ( uint16 fileNumber = 1; fileNumber <= fileCount; fileNumber++ )
{
AppleEvent fileEvent;
error = AECreateAppleEvent( 'MMPR',
'GFil',
&address,
kAutoGenerateReturnID,
kAnyTransactionID,
&fileEvent );
error.Debug();
error.Throw();
error = AEPutParamPtr( &fileEvent,
keyDirectObject,
typeSMInt,
&fileNumber,
sizeof( fileNumber ) );
error.Debug();
error.Throw();
error = AEPutParamPtr( &fileEvent,
'Segm',
typeSMInt,
&segmentNumber,
sizeof( segmentNumber ) );
error.Debug();
error.Throw();
AppleEvent fileReply;
error = AESend( &fileEvent,
&fileReply,
kAEWaitReply,
kAENeverInteract,
5 * 60 * 60,
0,
0 );
error.Debug();
error.Throw();
AERecord fileRecord;
error = AEGetParamDesc( &fileReply,
keyDirectObject,
typeAERecord,
&fileRecord );
bool found = error.OK();
error.Fix( errAECoercionFail );
error.Debug();
error.Throw();
error = AEDisposeDesc( &fileReply );
error.Debug();
error.Throw();
if ( !found )
continue;
int32 upToDate = 0;
int32 actualSize;
OSType type;
error = AEGetKeyPtr( &fileRecord,
'UpTD',
typeBoolean,
&type,
&upToDate,
sizeof( upToDate ),
&actualSize );
error.Debug();
error.Throw();
Assert( actualSize <= sizeof( upToDate ) );
if ( upToDate == 0 )
{
static BufferOfSize<64> name;
name.Reset();
error = AEGetKeyPtr( &fileRecord,
'pnam',
typeChar,
&type,
name.Unused().Start(),
name.Unused().Length(),
&actualSize );
error.Debug();
error.Throw();
name.AdvanceMark( actualSize );
String255 string( name.Used() );
SeeUncompiledFile( string );
}
error = AEDisposeDesc( &fileRecord );
error.Debug();
error.Throw();
}
error = AEDisposeDesc( &segmentRecord );
error.Debug();
error.Throw();
}
error = AEDisposeDesc( &segmentList );
error.Debug();
error.Throw();
error = AEDisposeDesc( &address );
error.Debug();
error.Throw();
}
void CWWatcher::SeeUncompiledFile( ConstPString name )
{
filesLeft++;
if ( !stats.Known( name ) )
stats.AddFile( name );
totalLines += stats.FileLines( name );
}